<?php
class RemindController extends AppController {

	public $name = 'remind';

	function beforeFilter() {
	    parent::beforeFilter(); 
		$this->C_auth->autoRedirect = false; //For override login
	    $this->C_auth->allowedActions = array('index','reminddel','remindedit','remindadd');

	}

	public function index() {
        $page = Request::get_args('page');
        $url_this = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $tb = array('model' => 'remindinfo',
				    'fields' => array('remindinfo.*'),
					'conditions' => array('user_id' => 0),
					'order' => ' remind_time desc ',
					'limit' => '10',
					'group' => '',
					'url' => preg_replace("/&page=([^&]+)/","",$url_this),
					'page' => $page,
					'plist' => 6				
				); 
	    $result =  $this->fpage($tb);	
        $this->set('result',$result);		
	}	
	public function remindadd() {        	
	    if(isset($this->data)) {
            /* post 数据处理 */
            $post['remind_info'] = Request::get_args('remind_info');
            $post['user_id'] = '0';
            $post['isread'] = '2';
            $post['remind_time'] = date("Y-m-d H:i:s");
	        $safeData['remindinfo'] = $post;				
			if(POP::exe('[@@:UM remindinfo][@@:QU save]',$safeData)) {
                $this->flash("修改成功！", Router::url('admin/remind/index/'));		        
            } else {	           
			    $this->flash("修改失败！", Router::url('admin/remind/index/'));   
            }			
		}
	}	
	
	public function remindedit() {
	    if(isset($this->data)) {
            $remind_info = Request::get_args('remind_info');
            $remind_time = date("Y-m-d H:i:s");
            $rinfo_id = intval(Request::get_args('rinfo_id'));
			$query  = array();		
			$query['keyid'] = $rinfo_id;
			$safeData['remindinfo'] = array('remind_info' => $remind_info,'remind_time' => $remind_time);				
			$query['set'] = $safeData;		
            if(POP::exe('[@@:UM remindinfo][@@:QU save]',$query)) {
                $this->flash("修改成功！", Router::url('admin/remind/index/'));		        
            } else {	           
			    $this->flash("修改失败！", Router::url('admin/remind/index/'));   
            }			
		}else {
	        $id=intval(Request::get_args('id'));
            if(!$id) { 
		        $this->flash("参数错误！", Request::referer()); 
		    }			
			$query = array(
				'conditions' => array('remindinfo.id' => $id), 
				'fields' => array('remindinfo.*'), 
			);
			$row = POP::exe('[@@:UM remindinfo][@@:QU find:first]',$query);			
		    $row = $row['remindinfo'];
            $this->set('row',$row);
        }		
	}		
	
	public function reminddel() {
	    $id=intval(Request::get_args('id'));
        if(!$id) { 
		    $this->flash("参数错误！", Request::referer()); 
		}
		$query = array('keyid'=>$id);		
        if(POP::exe('[@@:UM remindinfo][@@:QU del]',$query)) {
            $this->flash("删除成功！", Router::url('admin/remind/index/'));		        
        } else {	           
			$this->flash("删除失败！", Router::url('admin/remind/index/'));   
        }	
	}	
		

}

?>